﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Web.UI;
using WinnerCMS.BLL;
using WinnerCMS.BLL.PageFactory;
using WinnerCMS.BLL.PageFactory.TagModule;
using WinnerCMS.Common;

namespace WinnerCMS.WebFactory
{
    public class ShopSearchPage : PublicPage
    {

        protected string KeyWord = "";
        private int _PageNo;

        #region 重写事件
        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                if (int.TryParse(Request["PageNo"], out this._PageNo) == false)
                {
                    this._PageNo = 1;
                }


            }

        }

        #region 重写Render
        protected override void Render(HtmlTextWriter writer)
        {
            StringBuilder winner = new StringBuilder();
            using (TextWriter tempWriter = new StringWriter())
            {
                base.Render(new HtmlTextWriter(tempWriter));
                winner.Append(tempWriter.ToString());
            }

            string strMode = TagEngine.GetString(winner.ToString(), "PageList", GetWhich.All);
         

            string path = "<a href='" + StaticFilePath.IndexUrl() + "'>" + WebConfig.SiteName + "</a>" + "→ 搜索引擎 → 关键字：<font color=red><b> " + Request["KeyWord"] + "</b></font>";

            winner.Replace("[Path]", path);

            this.KeyWord = MyString.SQL_ESC(Request["KeyWord"]);


            IList<string> matchresult = TagEngine.TagCollection(winner.ToString(), "PageList");
            foreach (string nextmatch in matchresult)
            {
                winner.Replace(nextmatch, PageCommon.SearchContetnList(winner, 4, MyString.Left(Request["Sort"], 15), this.KeyWord, this._PageNo));
            }

            writer.Write(winner.ToString());
        }
        #endregion



    }
}
